package com.reesechou.ajax;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by 小星打屁屁 on 2015/3/18.
 * contact me ==>243709758@qq.com
 * 验证 随机码，当输入的随机码==session中所存的验证码时，输出TRUE
 *
 */
public class RandomNumAjax extends HttpServlet {
    public RandomNumAjax(){
        super();
    }
    protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        doPost(request, response);
    }
    protected void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException {
        String randomNum = request.getParameter("randomNum");
        String randomNumInSession = (String)request.getSession().getAttribute("randomNum");
        System.out.println("in RandomNumAjax randomNum = " +randomNum);
        System.out.println("in RandomNumAjax randomNumInSession = " +randomNumInSession);

        if(randomNumInSession.equals(randomNum)){

            response.getWriter().write("true");

        }else{
            response.getWriter().write("false");
        }
    }
}
